import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-03
 * Time: 14:44
 */
public class Test14 {

    public static int[][] merge(int[][] num) {
        List<int[]> ret = new ArrayList<>();
        //以左端点排序
        Arrays.sort(num,(v1,v2)->{
            return v1[0]-v2[0];
        });

        int left = num[0][0],right = num[0][1];

        for(int i = 0; i < num.length; i++) {
            int a = num[i][0], b = num[i][1];
            if(a <= right) {
                right = Math.max(b,right);
            }else {
                ret.add(new int[]{left,right});
                left = a;
                right = b;
            }
        }
        ret.add(new int[]{left,right});
        return ret.toArray(new int[0][]);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] num = new int[n][2];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 2; j++) {
                num[i][j] = sc.nextInt();
            }
        }
        int[][] ret = merge(num);

        // 格式化输出
        System.out.print("[");
        for(int i = 0; i < ret.length; i++) {
            System.out.print("[");
            for(int j = 0; j < 2; j++) {
                System.out.print(ret[i][j]);
                if(j < 1) {
                    System.out.print(",");
                }
            }
            System.out.print("]");
            if(i < ret.length-1) {
                System.out.print(",");
            }
        }
        System.out.print("]");
    }
}
